package com.hsxc.cdz.monitor.bean.server.v1_21;

import com.hsxc.cdz.base.util.BytesUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.ReferenceCountUtil;

/**
 * 
 * @author 刘力文 
 * 
 * 服务器下发交流桩注册响应报文的实体类
 *
 */
public class RegisterSerMsg extends ServerMessage {
	public static final int length = 26; // 报文体长度
	private String operator; // 运营商
	private String address; // 充电设备地址
	private long secretKey; // 秘钥
	private String vesion; // 软件版本号
	private String ipAdress; // 服务器IP地址
	private int port; // 端口号

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public long getSecretKey() {
		return secretKey;
	}

	public void setSecretKey(long secretKey) {
		this.secretKey = secretKey;
	}

	public String getVesion() {
		return vesion;
	}

	public void setVesion(String vesion) {
		this.vesion = vesion;
	}

	public String getIpAdress() {
		return ipAdress;
	}

	public void setIpAdress(String ipAdress) {
		this.ipAdress = ipAdress;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	@Override
	public byte[] getBytesFromMessage() {

		ByteBuf bytes = Unpooled.buffer(length);
		byte[] result;
		byte[] temp;
		temp = BytesUtil.strToBcdBytes(this.getOperator(), 2);
		bytes.writeBytes(temp);
		temp = BytesUtil.strToBcdBytes(this.getAddress(), 8);
		bytes.writeBytes(temp);
		temp = BytesUtil.longToBytesDesc(this.getSecretKey(), 8);
		bytes.writeBytes(temp);
		temp = BytesUtil.strToBcdBytes(this.getVesion(), 2);
		bytes.writeBytes(temp);
		temp = BytesUtil.adrressTobytes(this.getIpAdress());
		bytes.writeBytes(temp);
		temp = BytesUtil.intToBytesDesc(this.getPort(), 2);
		bytes.writeBytes(temp);
		result = new byte[bytes.readableBytes()];
		bytes.readBytes(result);
		ReferenceCountUtil.release(bytes);
		return result;
	}
}
